<template>
  <div class="container">
    <div class="content">
      <h1>调查问卷</h1>
      <form>
        <div class="form-row">
          <div class="form-col">
            <div class="form-group">
              <label for="name">姓名</label>
              <input type="text" id="name" v-model="form.name" required />
            </div>
          </div>
          <div class="form-col">
            <div class="form-group">
              <label for="gender">性别</label>
              <select id="gender" v-model="form.gender" required>
                <option value="">请选择</option>
                <option value="男">男</option>
                <option value="女">女</option>
                <option value="其他">其他</option>
              </select>
            </div>
          </div>
          <div class="form-col">
            <div class="form-group">
              <label for="idNumber">身份证号</label>
              <input
                type="text"
                id="pid"
                v-model="form.pid"
                required
                pattern="[0-9]{17}[0-9Xx]"
              />
            </div>
          </div>
          <div class="form-col">
            <div class="form-group">
              <label for="age">年龄</label>
              <input type="number" id="age" v-model="form.age" required />
            </div>
          </div>
          <div class="form-col">
            <div class="form-group">
              <label for="place">住址</label>
              <input type="text" id="place" v-model="place" required />
            </div>
          </div>
          <div class="form-col">
            <div class="form-group">
              <label for="contact">联系方式</label>
              <input type="text" id="contact" v-model="form.tel" required />
            </div>
          </div>
          <div class="form-col">
            <div class="form-group">
              <label for="symptoms">症状</label>
              <textarea id="symptoms" v-model="form.symptoms" required></textarea>
            </div>
          </div>
        </div>
        <button type="submit" @click="submit()">提交</button>
      </form>
      <div class="contact-section">
        <h2>联系我们</h2>
        <p>如果您有任何问题，请随时与我们联系：</p>
        <ul>
          <li>Email: questionnaire@questionnaire.com</li>
          <li>电话: 123-456-7890</li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, reactive } from "vue";
import axios from "axios";
const form = reactive({
  pid: "",
  name: "",
  tel: "",
  age: "",
  symptom: "",
  gender: "",
});

function submit() {
  axios
    .post(`/api/add`, form)
    .then((response) => {
      // 保存成功的处理逻辑
      console.log("保存成功", response.data);
      form.pid = "";
      form.name = "";
      form.tel = "";
      form.age = "";
      form.symptom = "";
      form.gender = "";
    })
    .catch((error) => {
      console.error("保存失败", error);
    });
}
</script>

<style scoped>
.container {
  background-color: white;
  max-width: 800px;
  margin: auto;
}

h1 {
  text-align: center;
}

.form-row::after {
  content: "";
  display: table;
  clear: both;
}

.form-col {
  width: 50%;
  float: left;
  box-sizing: border-box;
  padding: 0 10px;
}

.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  font-weight: bold;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 15px;
  font-size: 16px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

button[type="submit"] {
  display: block;
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.contact-section {
  margin-top: 40px;
  text-align: center;
}

.contact-section h2 {
  font-size: 24px;
}

.contact-section p {
  font-size: 16px;
  margin-bottom: 10px;
}

.contact-section ul {
  list-style-type: none;
  padding: 0;
}

.contact-section li {
  font-size: 16px;
  margin-bottom: 5px;
}
</style>
